/**
 * https://leetcode.cn/problems/teemo-attacking/
 */
function findPoisonedDuration(timeSeries: number[], duration: number): number {
  let totalTime = 0;

  for (let i = 0; i < timeSeries.length; i++) {
    if (totalTime > timeSeries[i]) {
        totalTime -= duration
        totalTime += timeSeries[i] - timeSeries[i - 1]
    }
    totalTime += duration;
  }

  return totalTime;
}
